package com.nmh.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nmh.entity.Enclosure;
import com.nmh.entity.EnclosureAndPasture;
import com.nmh.mapper.EnclosureMapper;
import com.nmh.service.EnclosureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yoki
 * @since 2023-12-19
 */
@Service
public class EnclosureServiceImpl extends ServiceImpl<EnclosureMapper, Enclosure> implements EnclosureService {
    @Autowired
    private EnclosureMapper enclosureMapper;

    @Override
    public List<EnclosureAndPasture> getall() {
        List<EnclosureAndPasture> selectall = enclosureMapper.selectall();
        return selectall;
    }

    @Override
    public boolean add(Enclosure enclosure) {
//        System.out.println("新增圈舍----------");
//        System.out.println(enclosure.getCircleName());
        enclosure.setState(1);
        Enclosure enclosure1 = enclosureMapper.selectByCircleName(enclosure);
        if (enclosure1 == null) {
//            System.out.println("可以新增");
            boolean insertone = enclosureMapper.insertone(enclosure);
            return insertone;
        }
//        System.out.println("重复");
        return false;
    }

    @Override
    public boolean modifyByState(Enclosure enclosure) {
        System.out.println("修改状态+++++++++++++++++");
        Enclosure enclosure1 = enclosureMapper.selectById(enclosure);
        System.out.println("要修改的具体信息");
        System.out.println(enclosure1);
        System.out.println(enclosure1.getState());
        if(1==enclosure1.getState())
        {
            enclosure1.setState(0);
            return enclosureMapper.updateState(enclosure1);
        }
        enclosure1.setState(1);
        return enclosureMapper.updateState(enclosure1);
    }

    @Override
    public List<EnclosureAndPasture> getByThree(EnclosureAndPasture enclosureAndPasture) {
        System.out.println("-----模糊查询----");
        return enclosureMapper.selectEByThree(enclosureAndPasture);
    }
}
